package com.equipment;

import com.util.EncodingUtil;

/**
 * 国标脱机激活C6
 * @author Administrator
 *
 */
public class ChineseActivateOBURequest {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "C6"; // 扩展代码
	private String PsamVerType = ""; // PSAM卡解密车辆密钥类型，1表示5903，2表示3903
	private String PsamDir = "";//PSAM目录
	private String KeyType = "";//密钥类型
	private String BstUnixTime="";	//BST中的Unixtime
	private String StartDate = ""; // 合同生效日期
	private String DueDate = ""; //合同失效日期

	private String BCC = ""; // 异或校验值

	public String getChineseActivateOBURequest(String psamVerType,String psamDir,String keyType,String startDate,String dueDate){
		this.PsamVerType = psamVerType;
		this.PsamDir = psamDir;
		this.KeyType = keyType;
		this.BstUnixTime=EncodingUtil.LongTosix(System.currentTimeMillis()/1000, 8).toUpperCase();
		this.StartDate = EncodingUtil.addzero(startDate, 4);
		this.DueDate = EncodingUtil.addzero(dueDate, 4);
		Length=EncodingUtil.desToHex((broadening+PsamVerType+PsamDir+KeyType+BstUnixTime+StartDate+DueDate).length()/2, 4);
		// DATA由代码+扩展子代码+目录编号
		String DATA =RSCTL+Length+ code + broadening+PsamVerType+PsamDir+KeyType+BstUnixTime+StartDate+DueDate;
		// 异或校验从RSCTL到DATA所有字节的异或值
		BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		String retn = STX + DATA+BCC ; // 拼接完整的请求
		return retn;
	}

}
